#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<pthread.h>
#include<sys/types.h>
#include<unistd.h>

void *mythread(void *arg)
{
	printf("child thread,pid==[%d],id==[%ld]\n",getpid(),pthread_self());
}

int main()
{
	//创建子线程
	pthread_t thread;
	int res = pthread_create(&thread,NULL,mythread,NULL);
	if(res != 0)
	{
		printf("pthread_creat error,[%s]",strerror(res));
		return -1;
	}
	printf("main thread,pid==[%d],id==[%ld]\n",getpid(),pthread_self());

	//设置线程为分离属性
	pthread_detach(thread);

	//子线程设置分离属性，则pthread_join不再阻塞，立刻返回
	int	ret = pthread_join(thread,NULL);
	if(ret != 0)
	{
		printf("pthread_join error:[%s]\n",strerror(ret));
	}
	
	//目的是为了让子线程能够执行起来
	sleep(1);
	return 0;
}
